'''
Company: TWL
Author: xue jian
Email: xuejian@kanzhun.com
Date: 2020-11-01 11:29:34
'''
from typing import List
class Solution:
    def kthSmallestPath(self, destination: List[int], k: int) -> str:
#         记录v的位置，按二进制方法做
        store = [i for i in range(destination[0])]
        store.append(destination[0]+destination[1])
        cnt = 1
        re = ''
        for i in range(destination[0]+destination[1]):
            re += 'H'
        def ans(re):
            for i in store[:-1]:
                re=re[:i]+'V'+re[i+1:]
            return re[::-1]
        while True:
            if cnt==k:
                return ans(re)
            i=0
            for i in range(len(store)-1):
                if store[i+1]!=store[i]+1:
                    for j in range(1, i+1):
                        store[j]+=1
                    store[0]=0 if i>0 else store[0]+1
                    cnt+=1
                    break
            
if __name__ == "__main__":
    solution = Solution()
    destination = [15,15]
    k=155117520
    # k = 2
    print(solution.kthSmallestPath(destination, k))